package info;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 数据库连接
 * @author zjfcdf
 *
 */
public class DbConn {

	/**
	 * 获取数据库连接
	 * @return: Connection, 数据库连接
	 */
    public static Connection GetConnection(){
    	
    	Connection con = null;
    	try{
    		Class.forName( "com.mysql.cj.jdbc.Driver" );// 加载MySql数据驱动
    	    con = DriverManager.getConnection( 
    	    		"jdbc:mysql://localhost:3306/e"
    	        	    	+ "?useUnicode=true&characterEncoding=UTF-8"
    	        	    	+ "&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true",
    	    				"root", 
    	    				"123456" );// 创建数据库连接
    	}
    	catch( Exception e ){
    		System.out.printf( "数据库连接失败\n" );
    		System.out.println(e.toString());
    	}
    	
    	return con;

    }

	
}
